package hypeerweb;

public class Neighbor extends NodeDelegate {
	private static final long serialVersionUID = 1L;

	public Neighbor(Node node) {
		delegate = node;
	}
	public void add(Node node) {
		delegate.addNeighbor(new Neighbor(node));
	}
	
	public void remove(Node node) {
		delegate.removeNeighbor(new Neighbor(node));
		Node parent = node.getConnections().getSmallestNeighborWithChildren();
		if(!delegate.equals(parent)) {
			delegate.addDownPointer(parent);
			parent.addUpPointer(delegate);
		}
	}
	
	public void replace(Node node, Node replacingNode) {
		delegate.replaceNeighbor(new Neighbor(node), new Neighbor(replacingNode));
	}
}
